import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from hyrobot.common import CHECK_POINT, STEP

from lib.webui_permission import  *


class c73305:
    name = '验证修改密码功能-73305' # 测试用例名字

# 初始化方法
    def setup(self):
        STEP(1, '登陆网站')
        wd = open_browser()
        user_login(wd)

    #清除方法
    def teardown(self):
        wd = get_global_webdriver()
        wd.quit()

    # 测试用例步骤
    def teststeps(self):
        # 获取webdriver对象 对应 已经登录好的浏览器
        driver = get_global_webdriver()
        # driver = webdriver.Firefox()
        time.sleep(2)
        STEP(2,"修改时全为空")
        driver.find_element(By.CSS_SELECTOR,
                    ".avatar-wrapper > span:nth-child(1)"
                                 ).click()
        time.sleep(2)
        driver.find_element(By.CSS_SELECTOR,
        "li.el-dropdown-menu__item:nth-child(1) > span:nth-child(1)"
                                 ).click()

        driver.find_element(By.CSS_SELECTOR, ".dialog-footer > .el-button--primary").click()
        change_ero = []
        empty0 = driver.find_element(By.CSS_SELECTOR,
        "div.el-form-item:nth-child(1) > div:nth-child(2) > div:nth-child(2)"
                                     ).text
        empty1 = driver.find_element(By.CSS_SELECTOR,
        "div.el-form-item:nth-child(2) > div:nth-child(2) > div:nth-child(2)"
                                     ).text
        empty2 = driver.find_element(By.CSS_SELECTOR,
        "div.el-form-item:nth-child(3) > div:nth-child(2) > div:nth-child(2)"
                                     ).text
        change_ero.append(empty0)
        change_ero.append(empty1)
        change_ero.append(empty2)
        expect_list0 = ["密码不能少于六位","请输入新密码","请再次输入密码"]
        CHECK_POINT("提示信息是否一致",expect_list0 == change_ero)
        driver.find_element(By.CSS_SELECTOR, ".el-dialog__footer:nth-child(3) .el-button--default > span").click()

        time.sleep(2)
        STEP(2, "修改时原密码错")
        driver.find_element(By.CSS_SELECTOR,
                            ".avatar-wrapper > span:nth-child(1)"
                            ).click()
        time.sleep(2)
        driver.find_element(By.CSS_SELECTOR,
                            "li.el-dropdown-menu__item:nth-child(1) > span:nth-child(1)"
                            ).click()
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys("54767658")
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-input__inner").send_keys("123123")
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input__inner").send_keys("123123")
        driver.find_element(By.CSS_SELECTOR, ".dialog-footer > .el-button--primary > span").click()
        wrong_prime = message_check(driver,
                      "body > div.el-notification.right > div > div.el-notification__content > p"
        )
        CHECK_POINT("提示信息是否一致",wrong_prime == "原密码输入错误")

        time.sleep(5)
        STEP(3, "修改时两次密码不一致")
        driver.find_element(By.CSS_SELECTOR,
                            ".avatar-wrapper > span:nth-child(1)"
                            ).click()
        time.sleep(2)
        driver.find_element(By.CSS_SELECTOR,
                            "li.el-dropdown-menu__item:nth-child(1) > span:nth-child(1)"
                            ).click()
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys("123456")
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-input__inner").send_keys("123412")
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input__inner").send_keys("1234123")
        driver.find_element(By.CSS_SELECTOR, ".dialog-footer > .el-button--primary").click()
        psw_different = driver.find_element(By.CSS_SELECTOR,
        ".el-form-item__error"
                                            ).text
        CHECK_POINT("提示信息是否一致", psw_different == "两次输入密码不一致")
        driver.find_element(By.CSS_SELECTOR, ".el-dialog__wrapper:nth-child(2) .el-dialog__close").click()

        time.sleep(2)
        STEP(4, "修改时成功并重新登录")
        driver.find_element(By.CSS_SELECTOR,
                            ".avatar-wrapper > span:nth-child(1)"
                            ).click()
        time.sleep(2)
        driver.find_element(By.CSS_SELECTOR,
                            "li.el-dropdown-menu__item:nth-child(1) > span:nth-child(1)"
                            ).click()
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys("123456")
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-input__inner").send_keys("123123")
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input__inner").send_keys("123123")
        driver.find_element(By.CSS_SELECTOR, ".dialog-footer > .el-button--primary > span").click()
        time.sleep(2)
        success_msg = message_check(driver,
         "body > div.el-notification.right > div > div.el-notification__content > p"
                                    )
        CHECK_POINT("提示信息是否一致", success_msg == "修改密码成功")
        time.sleep(6)
        driver.find_element(By.CSS_SELECTOR,
                            ".avatar-wrapper > span:nth-child(1)"
                            ).click()
        time.sleep(2)
        driver.find_element(By.CSS_SELECTOR, ".el-dropdown-menu__item:nth-child(2) > span").click()
        driver.find_element(By.NAME, "username").click()
        driver.find_element(By.NAME, "username").send_keys("editor3")
        driver.find_element(By.NAME, "password").send_keys("123123")
        driver.find_element(By.NAME, "password").send_keys(Keys.ENTER)
        expetced_words1 = "产品列表"
        time.sleep(1)
        key_words1 = driver.find_element(By.CSS_SELECTOR,
                                       '.no-redirect'
                                            ).text
        CHECK_POINT("验证是否为期待文字", expetced_words1 == key_words1)

        # 6-10 add
        STEP(5, "还原密码")
        driver.find_element(By.CSS_SELECTOR,
                                ".avatar-wrapper > span:nth-child(1)"
                                ).click()
        time.sleep(2)
        driver.find_element(By.CSS_SELECTOR,
                                "li.el-dropdown-menu__item:nth-child(1) > span:nth-child(1)"
                                ).click()
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys("123123")
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-input__inner").send_keys("123456")
        driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input__inner").send_keys("123456")
        driver.find_element(By.CSS_SELECTOR, ".dialog-footer > .el-button--primary > span").click()
